import { message, Modal } from "ant-design-vue";
import { createVNode, Ref } from "vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { revokePayableStatementApi } from "@/api/financialManagement/payableManagement/paymentApproval";
export default function OperationHook(state: {
  dialogOpts: Base.DialogOpts;
  drawerOpts: Base.DrawerOpts;
  emit: any;
  loading: Ref<boolean>;
  passData: Ref<PaymentApproval.ListRows>;
  init: () => void;
}) {
  const { passData, loading, emit, drawerOpts } = state;
  const revokePayableStatementHandle = () => {
    Modal.confirm({
      title: "正在进行撤销账单的操作，请再次确认!",
      icon: createVNode(ExclamationCircleOutlined),
      onOk() {
        loading.value = true;
        revokePayableStatementApi(passData.value.id as string)
          .then((res: any) => {
            const { code } = res;
            if (code === 200) {
              message.success("操作成功!");
              emit("submit");
            }
          })
          .finally(() => (loading.value = false));
      }
    });
  };
  // 查看费用
  const showFeeHandle = (row: Base.GeneraDataType) => {
    drawerOpts.title = "查看费用";
    drawerOpts.width = "1200px";
    drawerOpts.component = "ShowFee";
    drawerOpts.type = 1;
    drawerOpts.passData = row;
    drawerOpts.visible = true;
  };
  return {
    revokePayableStatementHandle,
    showFeeHandle
  };
}
